package com.livesource.client.web.sourceCode;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.livesource.client.LiveSourceGlobalVariables;
import com.livesource.client.utilities.ButtonClose;
import com.livesource.client.utilities.ButtonRefresh;
import com.livesource.client.utilities.LoadingPanel;
import com.livesource.client.web.sourceCode.filesTree.FilesTree;
import com.livesource.client.web.sourceCode.filesTree.FilesViewList;

/**
 * Show all the classes of the current project as a specification format.
 * 
 * @Feature
 */
public class SourceCodePage extends VerticalPanel {

	public static VerticalPanel featuresTreePanel = new VerticalPanel();
	public static VerticalPanel featureVisualizationPanel = new VerticalPanel();
	public static HorizontalPanel hpOptionsIcons = new HorizontalPanel();

	public SourceCodePage(String panelSelected) {

		this.add(hpTop(panelSelected));

		HorizontalPanel hp = new HorizontalPanel();

		featuresTreePanel.setSize("350px", "100%");

		featuresTreePanel.clear();
		featuresTreePanel.add(new LoadingPanel());

		hp.add(featuresTreePanel);

		featureVisualizationPanel.clear();
		featureVisualizationPanel.setSize("100%", "100%");
		featureVisualizationPanel.setSpacing(20);
		hp.add(featureVisualizationPanel);

		this.add(hp);
	}

	private HorizontalPanel hpTop(String panelSelected) {

		HorizontalPanel hp = new HorizontalPanel();

		hp.setSpacing(20);

		hp.add(new FilesViewList(panelSelected));

		hpOptionsIcons.setWidth("800px");
		hpOptionsIcons
				.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		hp.add(hpOptionsIcons);

		hp.add(new ButtonRefresh(buttonRefreshClickHandler()));

		hp.add(new ButtonClose());

		return hp;
	}

	private ClickHandler buttonRefreshClickHandler() {

		return (new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				FilesTree tree = new FilesTree(FilesViewList.VIEW_FEATURES,
						LiveSourceGlobalVariables.projectEntries);

				SourceCodePage.featuresTreePanel.clear();
				SourceCodePage.featuresTreePanel.add(tree);
			}
		});

	}

}
